package com.gaoqi.mq.Routing;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * 模拟rabbitMQ route 工作模式 消费者
 */
@Component
@Slf4j
public class RoutingConsumer {

    @RabbitListener(bindings = {
            @QueueBinding(
                    //设置临时队列
                    value = @Queue,
                    //设置绑定交换机
                    exchange = @Exchange(value = "directs",type = "direct"),
                    //设置route key
                    key = {"info","error","warn"}
            )
    })
    public void receive1MessageOfRouting(String message){
        log.info("消费者1:消费消息:{}",message);
    }

    @RabbitListener(bindings = {
            @QueueBinding(
                    //设置临时队列
                    value = @Queue,
                    //设置绑定交换机(type 默认direct)
                    exchange = @Exchange(value = "directs"),
                    //设置route key
                    key = {"warn"}
            )
    })
    public void receive2MessageOfRouting(String message){
        log.info("消费者2:消费消息:{}",message);
    }
}
